package com.goexcursion

import com.goexcursion.exception.UserNotExistException

class ExcursionService {

	def create(String name, String description, Long latitude, Long longitude, Long creatorId){
		
		def creator = User.get(creatorId)
		if(creator){
			Excursion excursion = new Excursion(name:name,description:description,latitude:latitude, longitude:longitude, creator:creator)
			excursion.save()
			return excursion
		}
		else{
			throw new UserNotExistException("User does not exist");
		}
	}
	
	def delete(Long id){
		Excursion.delete(id)
	}
	
	def update(Long id){
		
	}
	
	def positiveVote(Long id){
		def exc = Excursion.get(id)
		if(exc){
			exc.positiveVotes += 1
			exc.save()
			return exc.positiveVotes
		}
		else
			throw new UserNotExistException("User does not exist")
	}
	
	def negativeVote(Long id){
		def exc = Excursion.get(id)
		if(exc){
			exc.negativeVotes += 1
			exc.save()
			return exc.negativeVotes
		}
		else
			throw new UserNotExistException("User does not exist")
	}
}
